﻿//======================================================================
//
//        Copyright (C) 2015   
//        All rights reserved
//
//        filename : PutInCardDetailed
//        description : 半成品/成品卡入库明细

//        created by XXX at  20150821
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CardLogistics.Web.Components;
using System.Data;
using System.Text;

namespace CardLogistics.Web.MainPage.PutInCard.PutInCard
{
    public partial class PutInCardDetailedList : BasePage
    {
        private static readonly CardLogistics.DAL.PutInCard.PutInCardData DAL = new DAL.PutInCard.PutInCardData();
        private static readonly CardLogistics.DAL.PutInCard.PutInCard_DetailData DetailDAL = new DAL.PutInCard.PutInCard_DetailData();

        protected void Page_Load(object sender, EventArgs e)
        {
            WebUserControl_ToolBar1.DeleteEvent += new EventHandler(WebUserControl_ToolBar1_DeleteEvent);
            if (!IsPostBack)
            {
                BindDLL(ddlsupName, "basic_suppliers", "suppliersname", "suppliersid", " and STATUS=0 and ISDELETE=0");  //供应商
                BindDLL(ddlBasicType, "basic_basictype", "typename", "id", " and typeno=0 and  status<>1 and isdelete=0"); //芯片类型
                BindDLL(ddlCardType, "basic_cardtype", "cardtypename", "id", " and  status<>1 and isdelete=0"); //卡片类型
                BindRpt();
            }
        }

        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void WebUserControl_ToolBar1_DeleteEvent(object sender, EventArgs e)
        {
            string delId = this.hdf_Id.Value;
            if (!string.IsNullOrEmpty(delId))
            {
                string[] ids = delId.TrimEnd(',').Split(',');
                int resCount = 0;
                for (int i = 0; i < ids.Length; i++)
                {
                    string resStr = DAL.Delete(ids[i]);
                    if (resStr.Split(',')[0] == "ok")
                        resCount++;
                }
                BindRpt();
            }
        }

        /// <summary>
        /// 绑定Rpt数据
        /// </summary>
        private void BindRpt()
        {
            int recordCount = 0;
            int pageCount = 0;
            StringBuilder sbStr = new StringBuilder();
            sbStr.Append(" 1=1 ");
            if (PutInCardNo.Text.Trim().Length > 0)
                sbStr.Append(" and PUTINNO like '%" + PutInCardNo.Text.Trim().ToUpper() + "%' ");//入库编号
            //供应商
            if (ddlsupName.SelectedIndex != 0)
                sbStr.Append(" and SuppId='" + ddlsupName.Value + "'");
            //合同编号
            if (PConNo.Text.Trim().Length > 0)
                sbStr.Append(" and ConNo like '%" + PConNo.Text.Trim().ToUpper() + "%' ");
            //芯片类型
            if (ddlBasicType.SelectedValue != "" && ddlBasicType.SelectedValue != "0")
                sbStr.Append(" and BasicTypeId ='" + ddlBasicType.SelectedValue + "'");
            //卡片类型
            if (ddlCardType.SelectedValue != "" && ddlCardType.SelectedValue != "0")
            {
                sbStr.Append(" and CardTypeId='" + ddlCardType.SelectedValue + "'");
            }
            if (txt_StartPutInDate.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(PUTINDATE,'yyyy-MM-dd')>='" + txt_StartPutInDate.Text.Trim() + "'");//入库开始日期
            if (txt_EndPutInDate.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(PUTINDATE,'yyyy-MM-dd')<='" + txt_EndPutInDate.Text.Trim() + "'");//入库结束日期

       
            DataTable dt = CardLogistics.DAL.CommonData.QuickPage_Oracle("v_putincarddetailedrpt", "ID", " PUTINNO,PUTINDATE,StartNo,EndNo", WebPageSize, WebPageIndex, sbStr.ToString(), "*", out pageCount, out recordCount);
            SetNetPagerHtml(AspNetPager1, dt, rptList, recordCount);
            #region 导出数据
            //导出语句
            string strExpSql = "select PUTINNO 入库编号,suppliersname 供应商,conno 合同号,batchno 批次号,typename 芯片类型,cardtypename 卡片类型, to_char(PUTINDATE,'yyyy-MM-dd') 入库日期,Startno 开始卡号,Endno 结束卡号,DueNumber 应有数量,ActuNumber 实际数量,Price 单价,TotalPrice 总价 from v_putincarddetailedrpt where " + sbStr.ToString() + "order by PutinNo,PutinDate,StartNo,EndNo";
            if (!Page.IsClientScriptBlockRegistered("regExportSql"))
                Page.RegisterClientScriptBlock("regExportSql", "<script language=\"Javascript\">var qsql=\"" + Server.UrlEncode(strExpSql) + "\";</script>");
            #endregion
        }


        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            WebPageIndex = AspNetPager1.CurrentPageIndex;
            BindRpt();
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            BindRpt();
        }
    }
}